/**
 * Created by abdulazizalonizi on 7/18/17.
 */
import java.io.* ;
import java.util.Scanner;

public class Task4 {
    public static void main (String [] args)
    {
        try {

            FileInputStream fileIn = new FileInputStream("input3.txt");
            FileOutputStream oStream = new FileOutputStream("output2.txt");
            PrintWriter printW = new PrintWriter(oStream);
            Scanner fin = new Scanner(fileIn);

            String word1 = fin.next();
            String word2 = fin.next();
            fin.nextLine();
            String sent1 = fin.nextLine();
            String sent2 = fin.nextLine();
            fin.close();

            String sent1new = sent1.replaceAll(word1,word2);
            String sent2new = sent2.replaceAll(word1,word2);

            //System.out.print(sent2);
            //System.out.print(sent2new);

            printW.println(sent1new + "\n" + sent2new);


            printW.close();


        }
        catch(Exception Me)
        {
            System.out.println("Exception found !");
        }







    }
}
